package com.fuhailiu.opengl.view;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;

public class GLViewGroup extends GLView {

	private ArrayList<GLView> mChildren = null;

	public GLViewGroup(Context context) {
		super(context);
		mChildren = new ArrayList<GLView>();
	}

	public boolean addView(GLView glView) {
		return mChildren.add(glView);
	}

	public void addView(GLView glView, int index) {
		mChildren.add(index, glView);
	}

	public boolean removeView(Object glView) {
		return mChildren.remove(glView);
	}

	public GLView removeViewAt(int index) {
		return mChildren.remove(index);
	}

	public void removeAllViews() {
		mChildren.clear();
	}

	public int getChildCount() {
		return mChildren.size();
	}

	public GLView getChildAt(int index) {
		return mChildren.get(index);
	}

	@Override
	public void draw(GL10 gl) {
		int size = mChildren.size();
		for (int i = 0; i < size; i++)
			mChildren.get(i).draw(gl);
	}

	@Override
	public void release() {
		int size = mChildren.size();
		for (int i = 0; i < size; i++)
			mChildren.get(i).release();
	}

}
